package com.zhengwl.study.thread;


import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

/**
 * CLH队列锁 空间复杂度低 唯一的缺点是在NUMA系统结构下性能很差，一种解决NUMA系统结构的思路是MCS队列锁
 * @author wlzheng
 *
 */
public class CLHLock implements Lock {
	private AtomicReference<Node> tail = new AtomicReference<>();
	private ThreadLocal<Node> myNode = null;
	private ThreadLocal<Node> prevNode = null;

	private class Node {
		private volatile boolean locked = false;
	}
	
	public CLHLock() {
		tail.set(new Node());
		myNode = new ThreadLocal<Node>() {
			protected Node initialValue() {
				return new Node();
			}
		};
		prevNode = new ThreadLocal<Node>() {
			protected Node initialValue() {
				return null;
			}
		};
		
	}


	@Override
	public void lock() {
		// TODO Auto-generated method stub
		
	}

	

	@Override
	public void unlock() {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void lockInterruptibly() throws InterruptedException {
		// TODO Auto-generated method stub
		
	}


	@Override
	public boolean tryLock() {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public Condition newCondition() {
		// TODO Auto-generated method stub
		return null;
	}

}
